package servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.RemitoVO;


import cliente.BDelegate;

/**
 * Servlet implementation class Remito
 */
public class Remito extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Remito() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String remitos = (String) request.getParameter("textarea1");
		String cuit = request.getParameter("cuit");
		StringTokenizer nrosRems = new StringTokenizer(remitos,"-"); 
		List <Integer> numeros = new ArrayList<Integer>();
		while(nrosRems.hasMoreTokens()){
			numeros.add(Integer.parseInt(nrosRems.nextToken()));
		}
		//buscar los ordenes en la base de datos
		RemitoVO remito = new RemitoVO();
		BDelegate bd = new BDelegate();
		remito = bd.generarRemito(numeros,cuit);
		//armar el xml del remito
		
		request.setAttribute("remito",remito);
	    RequestDispatcher dispatcher = request.getRequestDispatcher("listado.jsp");
	    dispatcher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
